x = (1:128).' + 50*cos((1:128).'*2*pi/40);
hdct = dsp.DCT;
X = step(hdct, x);
% Set the DCT coefficients which represent less 
% than 0.1% of the total energy to 0 and 
% reconstruct the sequence using IDCT. 
[XX, ind] = sort(abs(X),1,'descend');
ii = 1;
while (norm([XX(1:ii);zeros(128-ii,1)]) <= 0.999*norm(XX))
ii = ii+1;
end
disp(['Number of DCT coefficients that represent 99.9%',...
'of the total energy in the sequence: ',num2str(ii)]); 
XXt = zeros(128,1);
XXt(ind(1:ii)) = X(ind(1:ii));
hidct = dsp.IDCT;
xt = step(hidct, XXt);
plot(1:128,[x xt]);
legend('Original signal','Reconstructed signal',...
 'location','best');